<?php
include_once "../../../../common.php";
?>
<h2>Catogorie&euml;n</h2>
<?php
$query = "SELECT * FROM ProductCatogorien WHERE CatogorieID IS NULL ORDER BY Naam";
$result = $_MySQL->runQuery($query);
?>
<ul class="catogorien">
<?php
while($row = mysql_fetch_assoc($result))
{
	?>
	<li>
	<?php
	if(catogorieHasSub($row['ID']))
	{
		echo '<a href="#" onClick="javascript: getSubCat(\''.$row['ID'].'\'); return false;">';
		echo "[+]";
		echo "</a>&nbsp;";
		echo '<a href="#" onClick="javascript: selecteerCatogorie(\''.$row['ID'].'\'); return false;">';
		echo $row['Naam'];
		echo "</a>";
		?>
		<ul id="cat<?=$row['ID'];?>"></ul>
		<?php
	}
	else
	{
		echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
		echo '<a href="#" onClick="javascript: selecteerCatogorie(\''.$row['ID'].'\'); return false;">';
		echo $row['Naam'];
		echo "</a>";
	}
	?>
	</li>
	<?php
}
?>
</ul>
<br />
<br />
<input type="button" value="Toevoegen" onclick="javascript: $('#catogorieToevoegen').toggle();"/>
<div id="catogorieToevoegen" style="display:none;">
<form action="?" method="post">
	Naam: <input type="text" name="Naam" />
	<input type="hidden" name="action" value="catToevoegen" />
	<br /><input type="submit" value=" Opslaan " />
</form>
</div>
<script>
	function getSubCat(id)
	{
		// check if empty
		if($('#cat'+id).children().length <= 0)
		{
			// uitklappen
			var url = 'factory/getSubCatogorie.php?id='+id;
			$('#cat'+id).load(url);
		}
		else
		{
			// inklappen
			$('#cat'+id).empty();
		}
	}

	function selecteerCatogorie(id)
	{
		var url = 'containers/catogorieBewerken.php?id='+id;
		$('#catogorieBewerken').load(url);
	}
</script>

